﻿@model IEnumerable<RMS.Models.ProblemGroup>

@{
    RMS.Models.ProblemGroup g1 = Model.FirstOrDefault(x => x.Id == 1);
    RMS.Models.ProblemGroup g2 = Model.FirstOrDefault(x => x.Id == 2);
    RMS.Models.ProblemGroup g3 = Model.FirstOrDefault(x => x.Id == 3);
    RMS.Models.ProblemGroup g4 = Model.FirstOrDefault(x => x.Id == 4);
    
    ViewBag.Title = "CostChart";
    int year = (int)ViewData["year"];
    var occurenceChart = new Chart(width: 450, height: 400, theme: ChartTheme.Green)
    
        .AddTitle("Cost in " + year.ToString())

        .AddSeries(
            name: g1.Name,
            chartType: "Line",
            markerStep: 1,
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
            yValues: new[] {
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==1&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==2&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==3&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==4&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==5&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==6&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==7&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==8&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==9&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==10&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==11&&x.Date.Year==year).Sum(x=>x.Cost),
                g1.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==12&&x.Date.Year==year).Sum(x=>x.Cost),
                            
            })

        .AddSeries(
            name: g2.Name,
            chartType: "Line",
            markerStep: 1,
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
            yValues: new[] {
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==1&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==2&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==3&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==4&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==5&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==6&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==7&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==8&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==9&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==10&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==11&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g2.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==12&&x.Date.Year==year).Sum(x=>x.Cost).ToString()              
            })

        .AddSeries(
            name: g3.Name,
            chartType: "Line",
            markerStep: 1,
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
            yValues: new[] {
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==1&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==2&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==3&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==4&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==5&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==6&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==7&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==8&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==9&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==10&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==11&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g3.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==12&&x.Date.Year==year).Sum(x=>x.Cost).ToString()              
            })

        .AddSeries(
            name: g4.Name,
            chartType: "Line",
            markerStep: 2,
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
            yValues: new[] {
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==1&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==2&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==3&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==4&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==5&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==6&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==7&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==8&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==9&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==10&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==11&&x.Date.Year==year).Sum(x=>x.Cost).ToString(),
                g4.Problems.SelectMany(x=>x.Occurrences).Where(x=>x.Date.Month==12&&x.Date.Year==year).Sum(x=>x.Cost).ToString()              
            });
    occurenceChart.AddLegend(title: "Problem Groups");
    occurenceChart.Write();
            
}


